<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
<html>
<head>
<style type="text/css">
	.tree-node {padding:0;}
</style>
  </head>
  <body>
  	<div class="easyui-layout" data-options="fit:true">
		<div data-options="region:'north',border:false">
			<fieldset>
    		<legend>过滤条件</legend>
    		<table style="width:100%">
    			<tr>条件查询</tr>
    		</table>
  		</fieldset>
		</div>
  		<div data-options="region:'center',border:false" style="padding-bottom: 33px">
            <div id="toolbar_message" class="toolbar"></div>
  			<table id="message_grid"></table>
		</div>
	</div>
	<script>
		$(function(){
			$('#toolbar_message').toolbar({buttons:[
	           	{name:'add',iconCls:'icon-add',text:'添加发送消息'},
	      	],handler:handler});
			
		    $('#message_grid').datagrid({
		    	url:'/message/content/page',
	    		pagination:true,
	    		singleSelect:true,
	    		pageSize:20,
	    		rownumbers:false,
	    		striped:true,
	    		fit:true,
	    		fitColumns:true,
	    		toorbar:'#toolbar_message',
	    		columns:[[
	    			{field:'id',title:'编号'},
	    			{field:'title',title:'消息标题'},
	    			{field:'type',title:'类型',formatter:function(v,r,i){
	    				var t = "系统消息";
	    				if(r.type == '3'){
	    					t="私信消息";
	    				}
	    				return t;
	    			}},
	        		{field:'sendId',title:'发送人'},
	        		{field:'content',title:'消息内容'},
	    			{field:'enabled',title:'启用标记'},
	        		{field:'createDt',title:'创建时间'},
	        		
	        		{field:'-',title:'操作',align:'center',formatter:function(v,r,i){
	        			var action = '<a href="#" onclick="toEdit('+r.id+');">编辑</a>&nbsp;&nbsp;';
	        			action = action+'<a href="#" onclick="delete('+r.id+');">删除</a>';
	        			action = '<a href="#" onclick="toEdit('+r.id+');">发送消息</a>&nbsp;&nbsp;';
						return action;
					}}
	    		]]
			 });
		});
		
		function handler() {
			if(this.name == 'search') return toSearch();
			if(this.name == 'add') return toAdd();
			var item = $('#message_grid').treegrid('getSelected');
			if(!item) return;
			switch(this.name) {
			case 'addSub': toAddSub(item);break;
			case 'edit': toEdit(item);break;
			case 'del': toDel(item);break;
			}
		}
		
		function toSearch() {
			$('#message_grid').treegrid('load',$('#qform').serializeArray());
		}
		
		function toAdd() {
			show({code:'admin_user_add',title:'发送消息',iconCls:'icon-add',uri:'add',width:800,height:800,
				options : {
					success : function(data) { 
						$('#message_grid').datagrid('reload'); 
					}
				}
			});
		}

		function toEdit(id) {
			show({code:'group_info_edit',title:'编辑用户信息',iconCls:'icon-edit',uri:'edit?id='+id,width:800,height:600,
				options : {
					success : function(data) { 
						$('#message_grid').datagrid('reload'); 
					}
				}
			});
		}
		
		function toDel(item) {
			$confirm('您确定要删除“'+item.modelName+'”模块信息吗？',function() {
				$.post('delete?id='+item.id,function(r) {
					if(r.code <= 0) return $error(r.msg);
					$('#message_grid').datagrid('reload');
					$prompt('删除成功');
				},'json');
			});
		}

		function doSave() {
			$.submit('#dataform',function(r) {
				if(r.code<0) return $alert(r.msg);
				$('#dialog').dialog('close');
				$('#message_grid').datagrid('reload');
				$prompt('保存成功');
			});
		}
	</script>
  </body>
</html>